#pragma once

#include <iostream>
#include <pthread.h>

namespace qds
{
    class task
    {
    public:
        friend std::ostream& operator<<(std::ostream& _cout, const task& t);


    task()
    {}

    task(int x, int y, char oper)
        : _x(x)
        , _y(y)
        , _operator(oper)
        {}

    ~task()
    {}

    int calculate()
    {
        int ret = 0;
        switch (_operator)
        {
            case '+':
                ret = _x + _y;
                break;
            case '-':
                ret = _x - _y;
                break;  
            case '*':
                ret = _x * _y;
                break;    
            case '/':
                ret = _x / _y;
                break;  
            case '%':
                ret = _x % _y;
                break;
            default:
                std::cout << "this is an unknown bug" << std::endl;
                break;                      
        }
        std::cout << "当前任务正在被:" << pthread_self() << "线程执行中" << 
        ",任务的具体内容是:" << _x << _operator << _y << "=" << ret << std::endl;
        return ret;
    }

    int operator()()
    {
        return calculate();
    }

    private:
    int _x;
    int _y;
    char _operator;

    };

    std::ostream& operator<<(std::ostream& _cout, const task& t)
    {
        _cout << t._x << t._operator << t._y;
        return _cout;
    }
}
